package net2;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.Scanner;
public class UdpDictClient {

    private static final SocketAddress address =
            new InetSocketAddress("localhost", 4090);

    public static void main(String[] args) throws IOException {
        DatagramSocket socket = new DatagramSocket();
        Scanner scanner = new Scanner(System.in);
        while (true) {
            byte[] resp = new byte[128];
            DatagramPacket packet = new DatagramPacket(resp, resp.length);

            System.out.print("请输入要翻译的英文(以.结尾):");
            byte[] req = scanner.next().getBytes();
            DatagramPacket request = new DatagramPacket(req, req.length, address);
            socket.send(request);
            System.out.println("翻译请求已发送...");

            socket.receive(packet);
            String answer = new String(packet.getData());

            System.out.println("结果：" + answer);
        }
    }
}

